package com.xxx.shetuan3.service.impl;

import com.xxx.shetuan3.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import sun.security.util.Password;
@Service
public class UserDetailsImpl implements UserDetailsService {
    @Autowired
    private UserService userService;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        System.out.println("执行了自定义逻辑");
        com.xxx.shetuan3.pojo.User user = userService.findUserByAccount(username);
        System.out.println("返回了user");
        String account=user.getAccount();
        if("".equals(account)|| account==null){
            throw new UsernameNotFoundException("用户名不存在");
        }
        String password = user.getPassword();
        String roles = user.getRole();
        System.out.println(account);
        System.out.println(password);
        System.out.println(roles);
        return new User(account,password, AuthorityUtils.commaSeparatedStringToAuthorityList(roles));
    }
}
